home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 32 / Amiga Format AFCD32 (Nov 1998, Issue 117).iso / -seriously_amiga- / programming / e / newgui / src / plugins / pl_gauge.e < prev    next >
Text File  |  1998-08-10  |  5KB  |  144 lines

  1. /* 
  2.  *  Gauge-Plugin 1.2   © 1997/1998 THE DARK FRONTIER (Grundler Mathias)
  3.  * -================-
  4.  * 
  5.  * Changes:
  6.  * --------
  7.  * 0.5: = First functionable Version (fixed width and height)
  8.  *
  9.  * 0.8: = Minor Bugfixes inside render() (wrong coordinates at the Border-Drawing!)
  10.  *
  11.  * 0.9: = BETA-Release
  12.  *      - Gauge is now resizeable!
  13.  *
  14.  * 1.0: = First Realease as "useful" Plugin
  15.  *      - Added Direction-Flag (now you are able to choose between Vertiacal and Horizontal Gauge)
  16.  *      - Gauge-state now no longer in Pixel (this could destroy the GUI at some reasons!),
  17.  *        now only percents (0-100) allowed!!
  18.  *
  19.  * 1.1: = New Features added
  20.  *      - User definable colors for the Gaugebar and the Text inside
  21.  *      - Now you cold turn on/off the text inside!
  22.  *
  23.  * 1.2: = New Features added
  24.  *      - smooth scrolling, now only the really unneeded Area are cleared (filled in Backcolor)
  25.  * 
  26.  * 
  27.  */
  28.  
  29. OPT     OSVERSION = 37
  30. OPT     PREPROCESS
  31. OPT     MODULE
  32.  
  33. MODULE  'graphics/rastport'
  34. MODULE  'graphics/gfx'
  35. MODULE  'graphics/gfxmacros'
  36. MODULE  'intuition/intuition'
  37. MODULE  'newgui/newgui'
  38. MODULE  'tools/textlen'
  39.  
  40. EXPORT  CONST   GAUGE = PLUGIN
  41.  
  42. EXPORT  CONST   GAUGE_HOR  = RESIZEX,
  43.                 GAUGE_VERT = RESIZEY
  44.  
  45. EXPORT OBJECT   gauge   OF plugin
  46. PRIVATE
  47.  wnd            :LONG                   -> WindowPTR
  48.  ta             :LONG                   -> Textattr - BackUP
  49.  showtext       :LONG                   -> Text anzeigen?
  50.  dir            :INT                    -> Lage (Direction)
  51.  space          :INT                    -> Abstand zwischen dem Rand und dem ausgefüllten
  52.  color          :INT                    -> Stiftfarbe
  53.  pen            :INT                    -> Farbe des Zeichenstiftes
  54.  state          :INT                    -> Status (Wieviel % gefüllt?)
  55.  len            :INT                    -> Länge des Textes
  56. ENDOBJECT
  57.  
  58. PROC gauge(backcolor=3,frontcolor=2,space=0,dir=GAUGE_HOR,initstate=0,showtext=TRUE) OF gauge
  59.  self.color:=backcolor
  60.   self.pen:=frontcolor
  61.    self.space:=space
  62.     self.dir:=dir
  63.      self.state:=initstate
  64.       self.showtext:=showtext
  65. ENDPROC
  66.  
  67. PROC min_size(ta,fh)                            OF gauge
  68.  DEF    xs,
  69.         ys
  70.   IF self.dir=GAUGE_HOR
  71.    ys:=fh+4
  72.     xs:=textlen('100 %',ta)+4
  73.   ELSE
  74.    ys:=fh*4
  75.     IF self.showtext=TRUE
  76.      xs:=textlen('100 %',ta)+4
  77.     ELSE
  78.      xs:=fh+4
  79.     ENDIF
  80.  ENDIF
  81.   self.len:=xs
  82.    self.ta:=ta
  83. ENDPROC xs,ys
  84.  
  85. PROC will_resize()                              OF gauge IS self.dir
  86.  
  87. PROC render(ta,x,y,xs,ys,w:PTR TO window)       OF gauge
  88.  DEF    str[6]:STRING,                          -> xxx %\0
  89.         rport=0,                                -> RastPort-Adresse
  90.         width=0,                                -> Länge des Gauge-Balkens (innen)
  91.         ox=0,oy=0                               -> Offsetx, offsety
  92.  IF self.wnd=NIL THEN self.wnd:=w
  93.   rport:=w.rport
  94.    stdrast:=rport
  95.       SetAPen(rport,1)                          -> schwart
  96.        Move(rport,x,y+ys)                       -> x----------x <- Ende                 -.
  97.        Draw(rport,x,y)                          -> |                                      \
  98.        Draw(rport,x+xs,y)                       -> x <- Start                             (
  99.       SetAPen(rport,2)                          ->     weiß                                > Rahmen zeichnen
  100.        Move(rport,x+xs,y+1)                     -> Ende       x <- Start (+1 Pixel!)      (
  101.        Draw(rport,x+xs,y+ys)                    -> \/         |                           /
  102.        Draw(rport,x+1,y+ys)                     -> x----------x                         -'
  103.       SetBPen(rport,self.color)
  104.       SetAPen(rport,self.color)
  105.        IF self.dir=GAUGE_VERT
  106.         width:=(ys*self.state)/100
  107.          RectFill(rport,x+1+self.space,y+1+ys+self.space-width,x+xs-self.space-1,y+ys-self.space-1)
  108.         SetAPen(rport,0)
  109.         SetBPen(rport,0)
  110.          RectFill(rport,x+1,y+1,x+xs-1,y+ys-width-1)            -> Sanftes Scrolling, weil nur der "überflüssige" Bereich gelöscht wird
  111.           ox:=x+2
  112.            oy:=y+(ys/2)                         ->x+2,y+(ys/2))
  113.        ELSE
  114.         width:=((xs*self.state)/100)-self.space
  115.          RectFill(rport,x+1+self.space,y+1+self.space,x+width-1,y+ys-self.space-1)
  116.         SetAPen(rport,0)
  117.         SetBPen(rport,0)
  118.          RectFill(rport,x+width+1+self.space,y+1,x+xs-1,y+ys-1) -> Sanftes Scrolling, weil nur der "überflüssige" Bereich gelöscht wird
  119.           ox:=x+((xs-self.len)/2)
  120.            oy:=y+ys-4
  121.        ENDIF      
  122.         IF self.showtext
  123.          stdrast:=rport
  124.           SetABPenDrMd(rport,self.pen,0,RP_JAM1)
  125.            TextF(ox,oy,'\d[3] %',self.state)
  126.           SetDrMd(rport,RP_JAM2)
  127.         ENDIF
  128. ENDPROC
  129.  
  130. PROC set(state)                                 OF gauge
  131.  IF state<0
  132.   state:=0
  133.  ELSEIF state>100
  134.   state:=100
  135.  ELSE
  136.   self.state:=state
  137.  ENDIF
  138.   ng_setattrsA([
  139.         NG_GUI,         self.gh,
  140.         NG_REDRAW,      self,
  141.         NIL,            NIL])
  142. ENDPROC 
  143.  
  144.